//
//  HistroyCollectionViewCell.m
//  LOL视频播放
//
//  Created by 花花蔡 on 2016/12/13.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

#import "HistroyCollectionViewCell.h"
#import "Public.h"
#import "UIImageView+WebCache.h"

@interface HistroyCollectionViewCell ()

@property(nonatomic,strong) UIImageView *imageView;
@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UILabel *countLabel;
@property(nonatomic,strong) UILabel *dateLabel;


@end


@implementation HistroyCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)setModel:(Model *)model {
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:model.picture] placeholderImage:[UIImage imageNamed:@"占位图"]];
    _titleLabel.text = model.title;
    _dateLabel.text = [model.date stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    _countLabel.text = [NSString stringWithFormat:@"视频:%@",model.count];
}

- (void)createCell {
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame) - 80 * KWidth_ScaleW)];
    _imageView.layer.cornerRadius = 7;
    _imageView.layer.masksToBounds = YES;
    
    [self.contentView addSubview:_imageView];
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_imageView.frame) + 7 * KWidth_ScaleW, CGRectGetWidth(self.frame), 18 * KWidth_ScaleW)];
    _titleLabel.font = [UIFont systemFontOfSize:13 * KWidth_ScaleW];
    [self.contentView addSubview:_titleLabel];
    
    _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleLabel.frame) + 2 *KWidth_ScaleW, CGRectGetWidth(self.frame)/2 + 20, 18* KWidth_ScaleW)];
    _dateLabel.font = [UIFont systemFontOfSize:12 * KWidth_ScaleW];
    _dateLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_dateLabel];
    
    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_dateLabel.frame), CGRectGetMaxY(_titleLabel.frame) + 2 *KWidth_ScaleW, CGRectGetWidth(_dateLabel.frame) - 40, 18 * KWidth_ScaleW)];
    _countLabel.font = [UIFont systemFontOfSize:13 * KWidth_ScaleW];
    _countLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_countLabel];
    
    
    _deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(screen_width/2 - 48 * KWidth_ScaleW, 5 * KWidth_ScaleW, 20, 20)];
    [_deleteBtn setImage:[UIImage imageNamed:@"collection_cell_delete_22x22_@2x的副本.png"] forState:UIControlStateNormal];
    [_deleteBtn addTarget:self action:@selector(reduceArray:) forControlEvents:UIControlEventTouchUpInside];
    _deleteBtn.alpha = 0;
    [self.contentView addSubview:_deleteBtn];
//    _imageView.backgroundColor = [UIColor lightGrayColor];
//    _titleLabel.text = @"Title --- Title___Title";
//    _dateLabel.text = @"2014-2-33 10:23";
//    _countLabel.text = @"视频:2323";
}

- (void)reduceArray:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(reduceArray:)]) {
        [_delegate reduceArray:self];
    }
}

@end
